package com.ws.ssmzongjie3.config;

import com.ws.ssmzongjie3.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan("com.ws.ssmzongjie3.controller")
@EnableWebMvc

public class SpringMvcConfig  implements WebMvcConfigurer {
    /**
     *创建视图解析器
     *@return
     */
    @Bean(name="viewResolver")
    public ViewResolver viewResolverInit(){
        InternalResourceViewResolver viewResolver=new InternalResourceViewResolver();
        viewResolver.setPrefix("/");//设置前缀
        viewResolver.setSuffix(".jsp");//设置后缀
        return viewResolver;
    }
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

   @Bean("multipartResolver")  //方法名是multipartResolver 或者bean中配置名字multipartResolver
   public MultipartResolver multipartResolver(){
       CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
       multipartResolver.setMaxUploadSize(100000000); //设置上传文件大小最大值
       return multipartResolver;
   }


//     拦截器方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截路径是/** 全部拦截
        // 排除路径是/dept/login  (不走拦截器)
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**").excludePathPatterns("/luyou/**","/houtai//**","/user/login"
                ,"/user/gerenzhongxin","/user/gerenxinxi","/houuser/houlogin","/houuser/tuichu","/**/add","/**/huixian","/user/xiugaixinxi","/user/mima","/user/xiugaimima","/dianzan/qianlist","/dianzan/insert","/user/tuichu","/collection/shoucang","/order/insert","/collection/qianlist","/collection/delete","/order/qianlist","/order/delete","/collection/paihang","/user/zhuce","/user/verifyPassword","/dianzan/delete","/user/checkUsername","/houuser/checkUsername");

    }
}
